home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / PRINTERR.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  5KB  |  127 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    p r i n t e r r . c                                             */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1989, 1992 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. /*--------------------------------------------------------------------*/
  13. /*                          RCS Information                           */
  14. /*--------------------------------------------------------------------*/
  15.  
  16. /*
  17.  *    $Id: PRINTERR.C 1.3 1993/04/11 00:32:05 ahd Exp $
  18.  *
  19.  *    Revision history:
  20.  *    $Log: PRINTERR.C $
  21.  *     Revision 1.3  1993/04/11  00:32:05  ahd
  22.  *     Global edits for year, TEXT, etc.
  23.  *
  24.  * Revision 1.2  1992/11/19  02:57:19  ahd
  25.  * drop rcsid
  26.  *
  27.  * Revision 1.1  1992/11/16  05:00:26  ahd
  28.  * Initial revision
  29.  *
  30.  */
  31.  
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <time.h>
  37. #include <errno.h>
  38.  
  39. #ifndef __GNUC__
  40. #include <dos.h>
  41. #include <io.h>
  42. #endif
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*                    UUPC/extended include files                     */
  46. /*--------------------------------------------------------------------*/
  47.  
  48. #include "lib.h"
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*    p r i n t e r r                                                 */
  52. /*                                                                    */
  53. /*    Perform a perror() with logging                                 */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. void prterror(const size_t lineno, const char *fname, const char *prefix)
  57. {
  58.    char buf[50];
  59.    char *s = strerror(errno);
  60.    int l = strlen( s );
  61.  
  62.    boolean redirect = ((logfile != stdout) && !isatty(fileno(stdout)));
  63.  
  64. /*--------------------------------------------------------------------*/
  65. /*    Drop extra new from error message if we have room in our        */
  66. /*    small buffer                                                    */
  67. /*--------------------------------------------------------------------*/
  68.  
  69.    if (( s[l-1] == '\n') & (l < sizeof buf ))
  70.    {
  71.       s = strcpy( buf, s);    /* Make buf copy of string we use below*/
  72.       s[l-1] = '\0';          /* Drop extra newline from string      */
  73.    }
  74.  
  75. /*--------------------------------------------------------------------*/
  76. /*           Display the message with option file location            */
  77. /*--------------------------------------------------------------------*/
  78.  
  79.    printmsg(2,"Run time library error in %s at line %d ...",
  80.             fname, lineno);
  81.  
  82.    printmsg(0,"%s: %s", prefix, s);
  83.    if ( redirect )
  84.       fprintf(stdout,"%s: %s\n", prefix, s);
  85.  
  86. #ifdef __TURBOC__
  87.    if (_osmajor >= 3 )
  88.    {
  89.       union REGS regs;
  90.       struct SREGS sregs;
  91.       regs.h.ah = 0x59;       /* Extended error information          */
  92.       regs.x.bx = 0x00;       /* Set up for call                     */
  93.       intdosx(®s, ®s, &sregs);
  94.  
  95.       printmsg(1,"Extended DOS Error Information: "
  96.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  97.                   (int) regs.x.ax, (int) regs.h.bh,
  98.                   (int) regs.h.bl, (int) regs.h.ch );
  99.  
  100.       if ( redirect )
  101.       {
  102.          fprintf(stdout, "Extended DOS Error Information: "
  103.             "Number = %d, Class = %d, Action = %d, Locus = %d",
  104.                   (int) regs.x.ax, (int) regs.h.bh,
  105.                   (int) regs.h.bl, (int) regs.h.ch );
  106.          fputc('\n',stdout);  /* Allows compiler to avoid generating
  107.                                  second almost duplicate literal str */
  108.       } /* if ( redirect ) */
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*               Abort if that is the suggested action                */
  112. /*--------------------------------------------------------------------*/
  113.  
  114.       switch( regs.h.bl )
  115.       {
  116.          case 0x04:
  117.          case 0x05:
  118.                bugout( lineno, fname);
  119.  
  120.          default:
  121.                break;
  122.       } /* switch */
  123.    } /* (_osmajor >= 3 ) */
  124. #endif
  125.  
  126. } /* printerr */
  127.